package com.dragon.webservice.test;

import cn.com.webxml.ArrayOfString;
import cn.com.webxml.WeatherWS;
import cn.com.webxml.WeatherWSSoap;

import javax.xml.ws.Endpoint;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: longtao
 * @Date: 2019/8/21
 * @Version: 1.0
 * @Description:
 */
public class Main {

    public static void main(String[] args) throws IOException {

//        URL resource = Main.class.getClassLoader().getResource("wsdl/WeatherWS.wsdl");
//        System.out.println(resource.getFile());
//        System.out.println(new File(resource.getFile()));


        String province = "广东";
        String city = "深圳";

        String cityCode = "";
        String provinceCode = "";
        WeatherWS ws = new WeatherWS();
        WeatherWSSoap weatherWSSoap = ws.getWeatherWSSoap();

        //获取省份代码
        ArrayOfString regionProvince = weatherWSSoap.getRegionProvince();
        provinceCode = findFromArrayStr(regionProvince, province);


        //获取城市代码
        ArrayOfString supportCityString = weatherWSSoap.getSupportCityString(provinceCode);
        cityCode = findFromArrayStr(supportCityString, city);

        //获取天气
        ArrayOfString weather = weatherWSSoap.getWeather(cityCode, "");
        for (String s : weather.getString()) {
            System.out.println(s);
        }
    }


    public static String findFromArrayStr(ArrayOfString arrayStr,String str){
        List<String> list = arrayStr.getString();
        for (String s : list) {
            String[] split = s.split(",");
            if (str.equals(split[0])){
                return split[1];
            }
        }
        return null;
    }


}
